﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using BrnMall.Manager.Manager.BusinessCard;
using BrnMall.Services;
using BrnMall.Web.Framework;
using BrnMall.Web.StoreAdmin.Models;

namespace BrnMall.Web.StoreAdmin.controllers
{
    public class BusinessCardController : BaseStoreAdminController
    {
        public ActionResult CardVerifyList(int pageSize = 15, int pageNumber = 1)
        {
            var result = UserCardManager.GetStoreCardVerify(WorkContext.StoreId, pageNumber, pageSize);
            var pageModel = new PageModel(pageSize, pageNumber, (int)result.TotalItems);
            var model = new CardVerifyListModel
            {
                Page = pageModel,
                Items = result.Items.Select(t => new CardVerifyModel
                {
                    Id = t.Id,
                    StoreId = t.StoreId,
                    User = Users.GetPartUserById(t.UId),
                    VerifyImg = t.VerifyImg,
                    VerifyState = t.VerifyState,
                    VerifyTime = t.VerifyTime,
                    VerifyType = t.VerifyType,
                    VerifyUser = Users.GetPartUserById(t.VerifyUid),
                }).ToList()
            };
            MallUtils.SetAdminRefererCookie(Url.Action("CardVerifyList"));
            return View(model);
        }

        public ActionResult CardVerify(int id,int state)
        {
            UserCardManager.VerifyCard(id, WorkContext.Uid, state);
            return PromptView("操作成功");
        }

        public ActionResult UserCardList(int pageSize = 15, int pageNumber = 1)
        {
            var result = UserCardManager.GetStoreUserCard(WorkContext.StoreId, pageNumber, pageSize);
            var pageModel=new PageModel(pageSize,pageNumber,(int)result.TotalItems);
            var model = new UserCardListModel
            {
                Page = pageModel,
                UserCards = result.Items.Select(card => new UserCardModel
                {
                    CardCode = card.CardCode,
                    CId = card.CId,
                    Favorite = card.Favorite,
                    Praised = card.Praised,
                    StoreId = card.StoreId,
                    User = Users.GetUserById(card.UId),
                    Views = card.Views,
                    IsVerify = card.IsVerify
                }).ToList()
            };
            return View(model);
        }

        //public ActionResult UserTimeLineList(int pageSize = 15, int pageNumber = 1)
        //{

        //}
    }
}
